package com.cxx.purchasecharge.dal.impl;

import javax.persistence.Query;

import org.apache.commons.collections.CollectionUtils;

import com.cxx.purchasecharge.core.model.persistence.GoodsStorage;
import com.cxx.purchasecharge.dal.GoodsStorageDao;
import com.cxx.purchasecharge.dal.common.MyGenericDaoImpl;

public class GoodsStorageDaoImpl extends MyGenericDaoImpl<GoodsStorage, Long> implements GoodsStorageDao {

	public GoodsStorageDaoImpl() {
		super(GoodsStorage.class);
	}

	@Override
	public GoodsStorage findByGoods(long goodsId) {
		String sql = "select s from GoodsStorage s where s.goods.id=?1";
		Query query = getEntityManager ().createQuery (sql, GoodsStorage.class);
		query.setParameter (1, goodsId);
		return CollectionUtils.isNotEmpty (query.getResultList ()) ? (GoodsStorage)query.getResultList ().get (0) : null;
	}

}
